package com.muqi.app.qlearn.student.org;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;

import com.bumptech.glide.Glide;

import com.muqi.app.qlearn.modles.GroupTeacherInfoCourseEntity;
import com.muqi.app.qlearn.modles.OrganizeList;
import com.muqi.app.qlearn.student.R;

import com.muqi.app.user.widget.ExpandableTextView;
import com.muqi.app.user.widget.SelectableRoundedImageView;

/**
 * Created by lizhanfeng on 2016/6/2.
 */
public class HomeFragment extends ScrollAbleFragment {
	private ListView mListview;
	private List<GroupTeacherInfoCourseEntity> mCourseList;// = new
															// ArrayList<GroupTeacherInfoCourseEntity>();
	private int mOneToOneItemNum = 0;
	private int mClassItemNum = 0;
	private HashMap<String, String> introData;
	private OrganizeList organizeList;

	private SelectableRoundedImageView orgAvatar;
	private TextView orgName;
	private TextView orgSimple;
	private TextView orgIntroduce;
	private TextView orgDis;
	private RelativeLayout orgLl;

	public void setOrganizeList(OrganizeList organizeList) {
		this.organizeList = organizeList;
	}

	public static HomeFragment newInstance(
			List<GroupTeacherInfoCourseEntity> courseList, int oneToOneItemNum,
			int classItemNum, HashMap<String, String> intro,
			OrganizeList organizeList) {
		HomeFragment homeFragment = new HomeFragment();
		homeFragment.setData(courseList);
		homeFragment.setItemNum(oneToOneItemNum, classItemNum);
		homeFragment.setIntroduction(intro);
		homeFragment.setOrganizeList(organizeList);
		return homeFragment;
	}

	private void setData(List<GroupTeacherInfoCourseEntity> courseList) {
		this.mCourseList = courseList;
	}

	private void setItemNum(int oneToOneItemNum, int classItemNum) {
		mOneToOneItemNum = oneToOneItemNum;
		mClassItemNum = classItemNum;
	}

	private void setIntroduction(HashMap<String, String> intro) {
		introData = intro;
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_list, container, false);
		View headerView = inflater.inflate(R.layout.teacher_info_header, null);
		
		mListview = (ListView) view.findViewById(R.id.listview);
		mListview.addHeaderView(headerView);
		mListview.setAdapter(new ArrayAdapter<String>(mActivity, R.layout.item_address));
	

		((TextView) headerView.findViewById(R.id.sample1).findViewById(
				R.id.titles)).setText("教师简介：");
		((TextView) headerView.findViewById(R.id.sample2).findViewById(
				R.id.titles)).setText("过往经历：");
		((TextView) headerView.findViewById(R.id.sample3).findViewById(
				R.id.titles)).setText("教学特点：");
		((TextView) headerView.findViewById(R.id.sample4).findViewById(
				R.id.titles)).setText("成果分享：");

		ExpandableTextView expTv1 = (ExpandableTextView) headerView
				.findViewById(R.id.sample1).findViewById(R.id.expand_text_view);
		ExpandableTextView expTv2 = (ExpandableTextView) headerView
				.findViewById(R.id.sample2).findViewById(R.id.expand_text_view);
		ExpandableTextView expTv3 = (ExpandableTextView) headerView
				.findViewById(R.id.sample3).findViewById(R.id.expand_text_view);
		ExpandableTextView expTv4 = (ExpandableTextView) headerView
				.findViewById(R.id.sample4).findViewById(R.id.expand_text_view);

		orgAvatar = (SelectableRoundedImageView) headerView
				.findViewById(R.id.circularImage);
		orgName = (TextView) headerView.findViewById(R.id.item_name);
		orgSimple = (TextView) headerView.findViewById(R.id.item_simple_name);
		orgIntroduce = (TextView) headerView.findViewById(R.id.item_introduce);
		orgDis = (TextView) headerView.findViewById(R.id.item_distance);
		orgLl = (RelativeLayout) headerView.findViewById(R.id.rl_org);
		if (organizeList != null && organizeList.logo != null) {
			orgLl.setVisibility(View.VISIBLE);
			Glide.with(getActivity()).load(organizeList.logo).dontAnimate()
					.placeholder(R.drawable.defalut_avatar_student)
					.into(orgAvatar);
			orgName.setText(organizeList.name);
			orgSimple.setText(organizeList.shortName);
			orgIntroduce.setText(organizeList.introduce);
			orgDis.setText(organizeList.distance + "km");
			orgLl.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					

				}
			});
		}
		// expTv1.setText("真的是好多的文字啊啊啊啊真的是好多的文字啊啊啊啊真的是好多的文字啊啊啊啊真的是好多的文字啊啊啊啊真的是好多的文字啊啊啊啊真的是好多的文字啊啊啊啊真的是好多的文字啊啊啊啊");
		// expTv2.setText("EnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglishEnglish");

		expTv1.setText(introData.get("introduce"));
		expTv2.setText(introData.get("tacching_texperience"));
		expTv3.setText(introData.get("tedian"));
		expTv4.setText(introData.get("teaching_share"));

	

		return view;
	}

	
	
	@Override
	public View getScrollableView() {
		return mListview;
	}
}
